package top.shiyiri.set;

import lombok.*;

/**
 * @author Aunean
 * @date 2022/1/5
 */
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Data
@EqualsAndHashCode
public class User implements Comparable<User>{
    private String name;
    private int age;


    //按照姓名从小到大排列，如果出现姓名相同的值，则按照年龄从小到大排列
    @Override
    public int compareTo(User o) {
        if (o.name.equals(name)) {
            return age - o.age;
        }
        return -o.name.compareTo(name);
    }
}
